<?php

class Message	extends  Sitebase  
{
	public function getName()
	{
		return '的留言';
	}
	public function showTpl()
	{
			
		$param['MOD_ID'] = $this->mod_E->id;
		$param['MOD_TITLE'] = $this->current_room_E->name.$this->getName();
		$modify_url = $this->action->getUrl("index","mod","message",array("siteid"=>$this->site_E->id,"roomid"=>$this->current_room_E->id,"modid"=>$this->mod_E->id));
		$param['MODIFY_URL'] = $modify_url;
		$tplshow = $this->getShowTpl($param);
		$data['html'] = $tplshow;
		$data['error'] = 0;
		return $data;
	}
	public function showSettingTpl()
	{
		$action = $this->action->getUrl("index","setting","modsetting",
								array("siteid"=>$this->site_E->id,
									   "roomid"=>$this->current_room_E->id,
									   "modid" =>$this->mod_E->id));
		
		$param['ACTION'] = $action;
		$param['MOD_TITLE'] = $this->mod_E->title;
		$del_url = $this->action->getUrl("index","setting","moddel",array("siteid"=>$this->site_E->id,"roomid"=>$this->current_room_E->id,"modid"=>$this->mod_E->id));
		$param['DEL_URL'] = $del_url;						
		$tplsetting = $this->getSettingTpl($param);
		$data['error'] = 0;
		$data['html'] = $tplsetting;
		return $data;
	}
	public function modsetting(&$mod_E, $request)
	{
		$name = $request->get('name');
		$mod_E->title = $name;
		$data['r'] = 0;
		return $data;
	}
	public function moddel(&$mod_E, &$current_room_E)
	{
		$modsort = $current_room_E->modsort;
		$modsort_arr = unserialize($modsort);
		$modsort_l = str_replace($mod_E->id.',', '', $modsort_arr['l']);
		if(!empty($modsort_l))
		$modsort_arr['l'] = $modsort_l;  
		$current_room_E->modsort = serialize($modsort_arr);
		
		Messages::deleteByModId($mod_E->id);
		$mod_E->delete();
		$data['error'] = 0;
		return $data;
	}
	private function getSettingTpl($param)
	{
		$tplsetting = '
		<form action="'.$param['ACTION'].'" method="post">
			<fieldset>    
				<div class="item">
					<label>应用名称：</label>
					<input type="text" name="name" size="15" maxlength="15" value="'.$param['MOD_TITLE'].'">    
				</div>
				
				<div class="item-submit">
					<span class="bn-flat-hot"><input type="submit" value="保存"></span>
					<a href="#" class="a_cancel_setting_panel">取消</a>
					<span class="setting-panel-ops">
						&nbsp;&nbsp;
						<a href="'.$param['DEL_URL'].'" class="a_delete_mod" title="真的要删除此应用?">删除</a>
					</span>    
				</div>  
			</fieldset>
		</form>';
		return $tplsetting;
	}
	private function getShowTpl($param)
	{
			$showtpl = '
						<div class="mod sort" id="'.$param['MOD_ID'].'">    
							<div class="hd">                
								<h2>        
									<span>'.$param['MOD_TITLE'].'</span>
									                                                                                        
									<span class="pl">                                        
									( <a href="">全部</a> )        
									</span>    
								</h2>    
								<div class="edit">            
									<a href="#"  class="a_lnk_mod_setting">设置</a>        
								</div>    
							</div>
							<div class="bd">
								<div class="board">
								
									<form class="j a_add_board" name="bpform" action="'.$param['MODIFY_URL'].'" method="post">
										<textarea name="text" class="board-text"></textarea>
										<span class="bn-flat"><input name="bp_submit" type="submit" value=" 留言 "></span>
									</form>
								</div>
							</div>
						</div>';
			$showtpl .= "
						<script type=\"text/javascript\">
						Do(function(){
							$(function(){
								$('#".$param['MOD_ID']." form').submit(function(e){
									var err = $(this).find('.attn'), blank = '请填写内容';
									if ($.trim(this.elements['text'].value) === '') {
										if ( err.length > 0 ) {
											err.html(blank);
										} else {
											$(this).append(' &nbsp; <span class=\"attn\">' + blank + '</span>');
										}
										return false;
									}
								});
							});
						});
						</script>";
			
			
		return $showtpl;
	}
}

?>
